package com.mz.ieann.dokit.utils

import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) 2020 wasu company, All rights reserved.
 * <p>------------------------------------------------------
 * <p> 时间日期格式转化
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2023/5/23
 */
object TimeUtil {

    val format1 = "yyyy年MM月dd日HH时mm分ss秒"
    val format2 = "yyyy-MM-dd HH:mm:ss"
    val format3 = "yyyy年MM月dd日"
    val format4 = "yyyy-MM-dd"
    val format5 = "HH时mm分ss秒"
    val format6 = "HH:mm:ss"
    val format7 = "HH:mm"
    val format8 = "mm:ss"

    /**
     * 日期转毫秒
     */
    fun formatTimeLong(time: String, format: String? = format2): Long{
        return runCatching {
            SimpleDateFormat(format, Locale.CHINA).parse(time)?.time?: 0L
        }.getOrDefault(0L)
    }

    /**
     * 毫秒转日期
     */
    fun formatTimeString(time: Long, format: String? = format2): String{
        return SimpleDateFormat(format, Locale.CHINA).format(Date(time))
    }

}